//
//  ViewController.m
//  24 Homework MD5 SHA-1 DES
//
//  Created by GivenBmli on 16/8/16.
//  Copyright © 2016年 GivenBmli. All rights reserved.
//

#import "ViewController.h"
#import "NSString+BMLDM5.h"
#import "AFNetworking.h"
#import "AFHTTPSessionManager.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UITextField *encryptText;
@property (weak, nonatomic) IBOutlet UITextField *decodeText;

@property (nonatomic, copy) NSString *parmeters;
@property (nonatomic, copy) NSString *parmeterser;
@property (weak, nonatomic) IBOutlet UILabel *labelOfContent16;
@property (weak, nonatomic) IBOutlet UILabel *labelOfContent32;

@end

@implementation ViewController

- (IBAction)encryptButton:(id)sender {
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    NSString *urlString = @"http://tool.zzblo.com/api/md5/encrypt";
    
   self.parmeters= [@"text=" stringByAppendingString:self.encryptText.text];
    
    [manager.requestSerializer setQueryStringSerializationWithBlock:^NSString * _Nonnull(NSURLRequest * _Nonnull request, id  _Nonnull parameters, NSError * _Nullable __autoreleasing * _Nullable error) {
        
        return _parmeters;
    }];
    [manager POST:urlString parameters:_parmeters progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        
        NSLog(@"%@", responseObject);
    
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];

    
}
- (IBAction)decodeButton:(id)sender {
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    NSString *urlString = @"http://tool.zzblo.com/api/md5/decrypt";
    
    self.parmeterser = [@"secret=" stringByAppendingString:self.decodeText.text];
    
    [manager.requestSerializer setQueryStringSerializationWithBlock:^NSString * _Nonnull(NSURLRequest * _Nonnull request, id  _Nonnull parameters, NSError * _Nullable __autoreleasing * _Nullable error) {
        
        return _parmeterser;
    }];
    [manager POST:urlString parameters:_parmeterser progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        
        NSLog(@"%@", responseObject);
        self.encryptText.text = [responseObject objectForKey:@"text"];
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];

}

- (IBAction)conversionMD5:(id)sender {
    self.labelOfContent32.text = [_parmeters stringWith32DM5Lower];
//    self.labelOfContent16.text = [_parmeterser stringWith16DM5Lower];
    

}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
